<?php

/* 会员 member */
class Fabric_shopModel extends BaseModel
{
    var $table  = 'fabric_shop';
    var $prikey = 'fabric_shop_id';
    var $_name  = 'fabric_shop';
	
    var $_relation = array(
		'has_sour_item' => array(
			'model' => 'sourcingitem',
			'type' => HAS_MANY,
            'foreign_key'   => 'fabric_shop_id',
            'dependent'     => true
		),
		'has_fabric_info' => array(
			'model' => 'fabric_info',
			'type' => HAS_MANY,
			'foreign_key' => 'fabric_shop_id',
			'dependent' => true,
		),
    	'has_fabric_order' => array(
    		'model' => 'fabric_order',
    		'type' => HAS_MANY,
    		'foreign_key' => 'fabric_shop_id',
    		'dependent' => true,
    	)
	);

    /*
     * 判断名称是否唯一
     */
    function unique($fabric_shop_name, $fabric_shop_id = 0,$user_id=0)
    {
        $conditions = "fabric_shop_name = '$fabric_shop_name'";
        $fabric_shop_id && $conditions .= " AND fabric_shop_id <> '" . $fabric_shop_id . "'";
        $user_id && $conditions .= " AND user_id <> '" . $user_id . "'";
        return count($this->find(array('conditions' => $conditions))) == 0;
    }
    
    function get_fs_name($id){
    	$sql = "SELECT fabric_shop_name FROM ".$this->table." WHERE fabric_shop_id=".$id;
    	return $this->db->getOne($sql);
    }
    
    //查询档口信息
    function get_merch_info($uid){
    	$user_mod=&m('member');
    	$fabric_type_mod=&m('fabric_type');
    	$fields="us.user_name,fs.fabric_shop_name,fs.if_show,fs.description,ft.fabric_type_name,address,phone_tel,phone_mob,email,is_qq,wx_sn";
    	$sql="select * from ".$this->table." fs left join ".$user_mod->table." us on us.user_id=fs.user_id left join ".$fabric_type_mod->table." ft on fs.type_id=ft.fabric_type_id where fs.user_id=".$uid;
    	$merch_list=$this->db->getAll($sql);
    	return current($merch_list);
    }
}

?>